package com.supplychain.scm.core.common.validator.json;

import com.alibaba.fastjson.JSONValidator;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class MustJSONValidator implements ConstraintValidator<MustJSON, String> {

	@Override
	public void initialize(MustJSON annotation) {
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		//为空返回
		if (StringUtils.isBlank(value)) {
			return true;
		}
		return JSONValidator.from(value).validate();
	}

}
